#include "BlockQueue.hpp"
#include <unistd.h>

void *rountine1(void *arg)
{
    BlockQueue<int> *bq = static_cast<BlockQueue<int> *>(arg);
    int num = 1;
    while (true)
    {
        sleep(1);
        std::cout << "producter, 生产了: " << num << std::endl;
        bq->Push(num);
        num++;
    }
}

void *rountine2(void *arg)
{
    BlockQueue<int> *bq = static_cast<BlockQueue<int> *>(arg);
    while (true)
    {
        // sleep(1);
        int n = bq->Pop();
        std::cout << "consumer, 消费了: " << n << std::endl;
    }
}

int main()
{
    BlockQueue<int> bq;
    // tid1为生产者。tid2为消费者
    pthread_t tid1, tid2;
    pthread_create(&tid1, nullptr, rountine1, &bq);
    pthread_create(&tid2, nullptr, rountine2, &bq);

    pthread_join(tid1, nullptr);
    pthread_join(tid2, nullptr);

    return 0;
}